/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.fraction;

import ohos.agp.components.AttrHelper;
import ohos.agp.components.Component;
import ohos.app.Context;

import com.xuexiang.xui_lib.component.GridLayout;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.ability.SnapHelperAblility;
import com.xuexiang.xuidemo.factory.AdapterFactory;
import com.xuexiang.xuidemo.fractionstacklayout.BaseFraction;
import com.xuexiang.xuidemo.util.JumpUtil;

/**
 * 中间件
 *
 * @since 2021-03-30
 */
public class ExpandFraction extends BaseFraction implements GridLayout.OnItemClickListener {
    private final int anInt2 = 2;
    private final int anInt3 = 3;
    private final int anInt9 = 9;

    @Override
    public int getUicontent() {
        return ResourceTable.Layout_fraction_expand;
    }

    @Override
    public void initComponent() {
        Context context = mComponent.getContext();
        GridLayout gridLayout = (GridLayout) mComponent.findComponentById(ResourceTable.Id_grid_layout);
        gridLayout.setSpanCount(anInt3);
        gridLayout.setSpacing(AttrHelper.vp2px(anInt2, context));
        gridLayout.setOnItemClickListener(this);
        gridLayout.setProvider(AdapterFactory.getInstance().getExpandAdapter(context));
    }

    @Override
    public void onItemClick(Component component, int position) {
        switch (position) {
            case anInt9:
                JumpUtil.jumpToAbility(mComponent.getContext(), SnapHelperAblility.class);
                break;
            default:
                break;
        }
    }
}
